/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package CreateClassFromSchema;

import com.sun.codemodel.JCodeModel;
import com.sun.tools.xjc.api.ErrorListener;
import com.sun.tools.xjc.api.S2JJAXBModel;
import com.sun.tools.xjc.api.SchemaCompiler;
import com.sun.tools.xjc.api.XJC;
import java.io.File;
import org.xml.sax.InputSource;
import org.xml.sax.SAXParseException;

/**
 *
 * @author ThanhTai
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        try {
            String output = "src";
            SchemaCompiler sc = XJC.createSchemaCompiler();
            sc.setErrorListener(new ErrorListener() {

                public void error(SAXParseException e) {
                    System.out.println("Error" + e.getMessage());
                }

                public void fatalError(SAXParseException saxpe) {
                    System.out.println("Fatal" + saxpe.getMessage());
                }

                public void warning(SAXParseException saxpe) {
                    System.out.println("Warning" + saxpe.getMessage());
                }

                public void info(SAXParseException saxpe) {
                    System.out.println("Info" + saxpe.getMessage());
                }
            });

            sc.forcePackageName("DTO");
            File schema = new File("src/xml6/Tasks.xsd");
            InputSource is = new InputSource(schema.toURI().toString());
            sc.parseSchema(is);
            S2JJAXBModel model = sc.bind();
            JCodeModel code = model.generateCode(null, null);
            code.build(new File(output));
            System.out.println("Finished");


        } catch (Exception e) {
            System.out.println("Error " + e.getMessage());
        }
    }

}
